package main.com.pyjioh.accounts;

import java.util.List;

import main.com.pyjioh.R;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public final class AccountsTypesListAdapter extends ArrayAdapter<AccountType> {
	private List<AccountType> accountTypes;
	private LayoutInflater mInflater;

	public AccountsTypesListAdapter(Activity context, List<AccountType> accountTypes) {
		super(context, R.layout.select_account_item, accountTypes);
		
		this.accountTypes = accountTypes;
		mInflater = context.getLayoutInflater();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ItemViewHolder itemViewHolder = null;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.select_account_item, parent, false);
			itemViewHolder = new ItemViewHolder();
			itemViewHolder.tvLabel = (TextView) convertView.findViewById(R.id.text_item);
			itemViewHolder.ivIcon = (ImageView) convertView.findViewById(R.id.icon_item);
			convertView.setTag(itemViewHolder);
		} else {
			itemViewHolder = (ItemViewHolder) convertView.getTag();
		}

		itemViewHolder.tvLabel.setText(accountTypes.get(position).title);
		itemViewHolder.ivIcon.setImageResource(accountTypes.get(position).resId);

		return convertView;
	}

	private class ItemViewHolder {
		public TextView tvLabel;
		public ImageView ivIcon;
	}
}
